package com.stlm2.controller;

import com.stlm2.dems.service.DdmGoodsService;
import com.stlm2.dems.service.ValueAddedServicesService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * Created by zlq on 2017/10/18.
 */
@Controller
@RequestMapping("/valueAddedServicesC")
public class ValueAddedServicesController {
    @Resource
    private ValueAddedServicesService valueAddedServicesService;
    /*zlq
* crm查询增值服务列表页面
* */
    @RequestMapping(value="/listView",produces="application/json;charset=UTF-8")
    public ModelAndView listView(ModelAndView modelAndView){
        modelAndView.setViewName("/valueAddedServices/list");
        return modelAndView;
    }
    /*
    *zlq
    * 添加增值服务
    * token:
    * name:名称
    *price：价格
    * detailsUrl：详情地址
    * warrantyPeriod:服务期限
    * valueAddedServicesType：服务类型 1:按次服务 2:按月服务
    * next：服务次数
    * label:标签
    *  valueAddedServicesKind:服务种类1:碎屏服务 2:延保服务3：进水服务
    *  state:状态
     */
    @ResponseBody
    @RequestMapping(value="/add.json",produces="application/json;charset=UTF-8")
    public  String add(ModelMap model, String token,String name,String price,String detailsUrl,String warrantyPeriod,String valueAddedServicesType,String next,String label,String valueAddedServicesKind,boolean state){
        String data=null;
        try {
            data=valueAddedServicesService.add(model,token,name,price,detailsUrl,warrantyPeriod,valueAddedServicesType,next,label,valueAddedServicesKind,state);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"添加失败",data);
        }
        return  data;
    }
    /*
*查询所有的增值服务名称
* zlq
 */
    @ResponseBody
    @RequestMapping(value="/getValueAddedServices.json",produces="application/json;charset=UTF-8")
    public  String getValueAddedServices(ModelMap model,String valueAddedServicesKindValue){
        String data=null;
        try {
            data=valueAddedServicesService.getValueAddedServices(model,valueAddedServicesKindValue);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    /*
   *CRM查询增值服务列表
   * zlq
   * token:
   * page:页码
    */
    @ResponseBody
    @RequestMapping(value="/getList.json",produces="application/json;charset=UTF-8")
    public  String getList(ModelMap model,String token ,String page,String valueAddedServicesKind){
        String data=null;
        try {
            data=valueAddedServicesService.getList(model,token,page,valueAddedServicesKind);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"查询失败",data);
        }
        return  data;
    }

    /*
    *zlq
    * 修改增值服务
    * token:
    * id:
    * name:名称
    *price：价格
    * detailsUrl：详情地址
    * warrantyPeriod:服务期限
    * valueAddedServicesType：服务类型 1:按次服务 2:按月服务
    * next：服务次数
    * valueAddedServicesKind:服务种类1:碎屏服务 2:延保服务3：进水服务
    * state:状态
     */
    @ResponseBody
    @RequestMapping(value="/modification.json",produces="application/json;charset=UTF-8")
    public  String modification(ModelMap model, String token,String id,String name,String price,String detailsUrl,String warrantyPeriod,String valueAddedServicesType,String next,String valueAddedServicesKind,boolean state){
        String data=null;
        try {
            data=valueAddedServicesService.modification(model,token,id,name,price,detailsUrl,warrantyPeriod,valueAddedServicesType,next,valueAddedServicesKind,state);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"修改失败",data);
        }
        return  data;
    }

    @ResponseBody
    @RequestMapping(value="/getDetails.json",produces="application/json;charset=UTF-8")
    public  String getDetails(ModelMap model, String token,String id){
        String data=null;
        try {
            data=valueAddedServicesService.getDetails(model,token,id);
        }catch (Exception e){
            e.printStackTrace();
            return  CodeContent.getModelByCode(0,"修改失败",data);
        }
        return  data;
    }
}
